package com.huirui.server.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huirui.server.mapper.OrderReturnReasonMapper;
import com.huirui.server.pojo.entity.OrderReturnReason;
import com.huirui.server.pojo.result.PageResult;
import com.huirui.server.service.OrderReturnReasonService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @author yujun
 * @description 针对表【t_order_return_reason(订单管理系统-退货原因表（存储预设的订单退货原因选项，供用户申请退货时选择）)】的数据库操作Service实现
 * @createDate 2025-12-02 10:27:42
 */
@Service
public class OrderReturnReasonServiceImpl extends ServiceImpl<OrderReturnReasonMapper, OrderReturnReason>
        implements OrderReturnReasonService {

    @Override
    public void saveReason(OrderReturnReason orderReturnReason) {
        OrderReturnReason reason = BeanUtil.copyProperties(orderReturnReason, OrderReturnReason.class);
        reason.setCreateTime(LocalDateTime.now());
        save(reason);
    }

    @Override
    public void updateReason(OrderReturnReason orderReturnReason) {
        updateById(orderReturnReason);
    }

    @Override
    public void updateReturnReasonStatus(Long returnReasonId, Integer status) {
        lambdaUpdate()
                .eq(OrderReturnReason::getId, returnReasonId)
                .set(OrderReturnReason::getStatus, status)
                .update();
    }


    @Override
    public void deleteReturnReason(Long returnReasonId) {
        lambdaUpdate()
                .eq(OrderReturnReason::getId, returnReasonId)
                .remove();
    }

    @Override
    public PageResult<OrderReturnReason> listReturnReasons(Long page, Long pageSize) {
        IPage<OrderReturnReason> iPage = new Page<>(page, pageSize);
        lambdaQuery()
                .orderByDesc(OrderReturnReason::getCreateTime)
                .page(iPage);
        return PageResult.from(iPage);
    }
}




